#include <iostream>
#include <cstring>
#include "glutproject.h"

using namespace std;
using namespace bend2d;

class myGlutProject : public GlutProject
{
    public:
        int width;
        int height;
        int word;
        int buffsize;
        unsigned char * buff;
        
        myGlutProject() : GlutProject()
        {
            cout << "Created\n";
            buff = NULL;
        }
        
        void CustomRenderFunction()
        {
            cout << "Input data size: " << buffsize << "\n";
            glDrawPixels(width, height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, buff);
            
        }

        void SetOrtho()
        {
            gluOrtho2D(0, width, 0, height);
        }

        void CustomIdleFunction()
        {
            if(buff == NULL)
            {
                buffsize = width * height * word;
                buff = new unsigned char[buffsize];
            }

            memset(buff, 0, buffsize);
            if(cin.read((char*)buff, buffsize))
            {
                RenderFunction();
            }

        }
};

int main(int argc, char* argv[])
{
    myGlutProject project;
 
    project.width = atol(argv[1]);
    project.height = atol(argv[2]);
    project.word = atol(argv[3]);
 
    project.Init(argc, argv);
    project.MainLoop();
}

